//  [10/11/2013 OMEGA] created

#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>
#include <QActionGroup>
#include <QtWidgets/QBoxLayout>
#include "DuelGUIECommon.h"
#include "DuelGUIEEditView.h"
#include "DuelGUIEEditPanelContainer.h"



DGUIEEditView::DGUIEEditView( DGUIEWorkbench* workbench, QWidget* parent /*= 0*/ ) :
	QWidget(parent), 
	mWorkbench(workbench),
	mViewModeActGrp(new QActionGroup(this)),
	mSigleViewAct(new QAction(this)),
	mDualViewAct(new QAction(this)),
	mQuadViewAct(new QAction(this)),
	mSinglePanel(new DGUIEEditPanelSingleContainer(this)),
	mDualPanel(new DGUIEEditPanelDualContainer(this)),
	mQuadPanel(new DGUIEEditPanelQuadContainer(this))
{
	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->setMargin(0);
	layout->setSpacing(0);

	mViewModeActGrp->setExclusive(true);
	mSigleViewAct->setCheckable(true);
	mDualViewAct->setCheckable(true);
	mQuadViewAct->setCheckable(true);
	mViewModeActGrp->addAction(mSigleViewAct);
	mViewModeActGrp->addAction(mDualViewAct);
	mViewModeActGrp->addAction(mQuadViewAct);

	connect(mSigleViewAct, SIGNAL(triggered(bool)), this, SLOT(switchSiglePanel(bool)));
	connect(mDualViewAct, SIGNAL(triggered(bool)), this, SLOT(switchDualPanel(bool)));
	connect(mQuadViewAct, SIGNAL(triggered(bool)), this, SLOT(switchQuadPanel(bool)));

// 
// 	QPushButton* butn = new QPushButton(this);
// 	layout->addWidget(butn);
	changeViewMode(QUAD_VIEW);
}

DGUIEEditView::~DGUIEEditView()
{
// 	delete mSinglePanel;
// 	delete mDualPanel;
// 	delete mQuadPanel;
}

void DGUIEEditView::changeViewMode( ViewMode mode )
{
	switch (mode)
	{
	case DGUIEEditView::SINGLE_VIEW:
		mSigleViewAct->trigger();
		break;
	case DGUIEEditView::DUAL_VIEW:
		mDualViewAct->trigger();
		break;
	case DGUIEEditView::QUAD_VIEW:
		mQuadViewAct->trigger();
		break;
	default:
		break;
	}
}

void DGUIEEditView::switchSiglePanel(bool flag)
{
	if (flag)
	{
		layout()->removeWidget(mSinglePanel);
		layout()->removeWidget(mDualPanel);
		layout()->removeWidget(mQuadPanel);
		mSinglePanel->setEnabled(true); mSinglePanel->setVisible(true);
		mDualPanel->setEnabled(false); mDualPanel->setVisible(false);
		mQuadPanel->setEnabled(false); mQuadPanel->setVisible(false);
		layout()->addWidget(mSinglePanel);
	}
}

void DGUIEEditView::switchDualPanel(bool flag)
{
	if (flag)
	{
		layout()->removeWidget(mSinglePanel);
		layout()->removeWidget(mDualPanel);
		layout()->removeWidget(mQuadPanel);
		mSinglePanel->setEnabled(false); mSinglePanel->setVisible(false);
		mDualPanel->setEnabled(true); mDualPanel->setVisible(true);
		mQuadPanel->setEnabled(false); mQuadPanel->setVisible(false);
		layout()->addWidget(mDualPanel);
	}
}

void DGUIEEditView::switchQuadPanel(bool flag)
{
	if (flag)
	{
		layout()->removeWidget(mSinglePanel);
		layout()->removeWidget(mDualPanel);
		layout()->removeWidget(mQuadPanel);
		mSinglePanel->setEnabled(false); mSinglePanel->setVisible(false);
		mDualPanel->setEnabled(false); mDualPanel->setVisible(false);
		mQuadPanel->setEnabled(true); mQuadPanel->setVisible(true);
		layout()->addWidget(mQuadPanel);
	}
}
